<template>
    <el-dialog title="收货地址" :visible.sync="dialogFormVisible">
        <el-form :model="form">
            <el-form-item label="标题" :label-width="formLabelWidth">
                <el-input v-model="form.title" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="内容" :label-width="formLabelWidth">
                <el-input v-model="form.content" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="作者" :label-width="formLabelWidth">
                <el-input v-model="form.author" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="Submit">确 定</el-button>
        </div>
    </el-dialog>
</template>

<script>
export default {
    data() {
        return {
            dialogFormVisible: false,
            form: {
                title:"",
                content:"",
                author:"",
            },
            formLabelWidth: '120px'
        }
    },
    methods:{
        Submit() {
            if(this.form.id) {
                this.$api.editList(this.form).then(res=>{
                if(res.code===1){
                    this.$message({
                        type:"success",
                        message:'编辑成功'
                    })
                    // 这里怎么通知父组件刷新列表
                    this.$emit('update')
                    // 关闭弹框
                    this.dialogFormVisible = false;
                }
            })
            } else {
                this.$api.addList(this.form).then(res=>{
                if(res.code===1){
                    this.$message({
                        type:"success",
                        message:'添加成功'
                    })
                    // 这里怎么通知父组件刷新列表
                    this.$emit('update')
                    // 关闭弹框
                    this.dialogFormVisible = false;
                }
            })
            }
            
        }
    }
}
</script>

<style>

</style>